#include "Motor.h"

Motor::Motor()
{}

Motor::~Motor()
{}

void Motor::attach(uint8_t pwmPin, uint8_t ctrlPin)
{
	  pwmPin_ = pwmPin;
	  ctrlPin_ = ctrlPin;
	  pinMode(pwmPin, OUTPUT);
	  pinMode(ctrlPin, OUTPUT);
}

void Motor::mode(MotorMode m)
{
	mode_ = m;
}

void Motor::speedUp(int val)
{
	uint8_t ctrl = 0;
	switch(mode_) {
	case MODE_CW:
		ctrl = HIGH;
		break;
	case MODE_CCW:
		ctrl = LOW;
		break;
	case MODE_SHORT_BRAKE:
	default:
		break;
	}
	digitalWrite(ctrlPin_, ctrl);
	analogWrite(pwmPin_, val);
}

void Motor::shortBrake()
{
	speedUp(0);
}

